from pathlib import Path

# 1.1.1
# create absolute path object
p = Path("D:\\天气查询\\Generic\\using-python-to-process-excel-u\\第1章\\供应商信息表.xlsx")
# p = Path(r"D:\天气查询\Generic\using-python-to-process-excel-u\第1章\供应商信息表.xlsx")
# p = Path("D:/天气查询/Generic/using-python-to-process-excel-u/第1章/供应商信息表.xlsx")
print(p)
# output
# D:\天气查询\Generic\using-python-to-process-excel-u\第1章\供应商信息表.xlsx

# 1.1.2
# get current work directory absolute path object
p1 = Path.cwd()
# get current use directory absolute path object
p2 = Path.home()
print(p1)
print(p2)

# 1.1.3
# break down appoint path and get part of path
# break down by path separator return tuple
p_parts = p.parts
a = p_parts[0]
b = p_parts[1]
print(p_parts)
print(a)
print(b)

# 1.1.4
# parent and parents attribute for get high level path
p_parent1 = p.parent
p_parent2 = p.parent.parent
print(p_parent1)
print(p_parent2)

file_parent1 = p.parents[1]
file_parent2 = p.parents[2]
file_parent = p.parents
print(file_parent1)
print(file_parent2)
for i in file_parent:
    print(i)
# 1.1.5
# use name and stem attribute
# get file full name,include extend name
file_name = p.name
# get file  main name,not include extend name
file_stem = p.stem
# first get path ,second get folder name
folder_name = p.parent.name
folder_stem = p.parent.stem
print(file_name)
print(file_stem)
print(folder_name)
print(folder_stem)

# 1.1.6
# get file extend name by suffix return string
file_suffix = p.suffix
# get file extend name by suffixes return list
file_suffixes = p.suffixes
p2 = Path("D:\\天气查询\\Generic\\using-python-to-process-excel-u\\第1章\\library.tar.gz")
file_suffix2 = p2.suffix
file_suffixes2 = p2.suffixes
print(file_suffix)
print(file_suffixes)
print(file_suffix2)
print(file_suffixes2)

# 1.1.7
# / and join path() function
# join path(path1,path2,path3...) at least exist one path object
path1 = Path("D:\\天气查询\\Generic")
path2 = "using-python-to-process-excel-u\\第1章"
path3 = "供应商信息表.xlsx"
p3 = path1.joinpath(path2,path3)
print(p3)
